import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Artice } from 'src/interface/artice.interface';

@Injectable()
export class ArticeService {
    constructor(@InjectModel('artice')private readonly articeModel){}

    async findAll():Promise<Artice>{
        return await this.articeModel.find().exec()
    }

    async findOne(id):Promise<Artice>{
        return await this.articeModel.findOne(id)
    }

    async create(json:Artice){
       let artice = this.articeModel(json)
       await artice.save()
       return {
           message:'success'
       }
    }

    async deleteOne(_id){
        await this.articeModel.deleteOne(_id)
        return {
            message:'delete success'
        }
    }

    async put(id,body){
        await this.articeModel.update(id,body)
        return {
            message:'update success'
        }
    }
}
